<template>
	<view class="">
		<view class="" v-if="identity == 1" v-cloak>
			<userIndex ref="userIndex"></userIndex>
		</view>
		<view class="" v-if="identity == 2" v-cloak>
			<serverIndex ref="serverIndex"></serverIndex>
		</view>
		<view class="" v-if="identity == 3" v-cloak>
			<PickPersonIndex :list='list'></PickPersonIndex>
		</view>
		<view class="" v-if="identity == 4" v-cloak>
			<storagePersonIndex></storagePersonIndex>
		</view>

		<u-loading-page :loading="isLoading" loadingText='切换身份中'></u-loading-page>

		<pullUp :status='state'></pullUp>
		<tabbar :value="1"></tabbar>
	</view>
</template>

<script>
	import userIndex from '@/components/sharePage/user/index/index.vue'
	import serverIndex from '@/components/sharePage/server/index/index.vue'
	import PickPersonIndex from '@/components/sharePage/PickPerson/index/index.vue'
	import storagePersonIndex from '@/components/sharePage/storagePerson/index/index.vue'

	import {
		pageSize
	} from '@/components/minxinsa.js' //引入minxins

	import {
		mapGetters,
		mapState
	} from 'vuex';
	export default {
		components: {
			userIndex,
			serverIndex,
			PickPersonIndex,
			storagePersonIndex
		},
		mixins: [pageSize],
		data() {
			return {
				list: [], //
			}
		},
		onPullDownRefresh() { //下拉刷新
			this.$nextTick(() => {
				if (this.identity == 2) {
					this.$refs.serverIndex.shopIndex()
				} else if (this.identity == 3) {
					this.resetlist()
				}
			})
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000)
		},
		onLoad() {
			uni.setNavigationBarTitle({ //修改导航栏文字
				title: this.identity < 3 ? '首页' : '任务大厅'
			})
			if (this.identity == 3) { //取货员端
				this.getPickOrderList(2)
			}
		},
		onShow() {
			this.getUser()
		},
		methods: {
			getPickOrderList(e) { //取货员订单列表
				this.method_name = 'pickOrderList'
				this.query = {
					type: e
				}
				this.getList()
			},
		},
		computed: {
			...mapState({
				identity: state => state.identity,
			})
		},
		watch: {
			identity: {
				handler(news) { //1用户端 2服务端 3送货员 4入库员
					this.$nextTick(() => {
						if (news == 1) {
							this.$refs.userIndex.getUserIndex()
						} else if (news == 2) {
							this.$refs.serverIndex.shopIndex()
						}
					})
				},
				deep: true,
				immediate: true,
			},
		}
	}
</script>

<style lang="scss" scoped>
	[v-cloak] {
		display: none;
	}
</style>
